package cn.kgc.shiro.web.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.shiro.web.entity.User;
import cn.kgc.shiro.web.service.UserService;
import cn.kgc.shiro.web.mapper.UserMapper;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
* @author mengshun
* @description 针对表【user】的数据库操作Service实现
* @createDate 2024-06-04 08:54:53
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>implements UserService{


    @Override
    public Map<String, Object> registerUser(User user) {

        //  用户的明文密码加密处理    salt
        String password = user.getPassword();
        String salt = RandomUtil.randomString(8);

        String hex = new Md5Hash(password, salt, 10).toHex();
        user.setPassword(hex);
        user.setSalt(salt);

        baseMapper.insert(user);

        HashMap<String, Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","注册成功");
        return result;
    }
}




